#!/bin/bash

path=`find / -name nginx | grep sbin/nginx`
nginx_pid=/usr/local/nginx/logs/nginx.pid

case $1 in
	start)
#	netstat -anput | grep nginx &>/dev/null 
	[ -e $nginx_pid ] 
	if [ $? -eq 0 ];then
		exit
	else
		$path
		echo "nginx已启动"
	fi
;;
	stop)
#       netstat -anput | grep nginx &>/dev/null  
        [ -e $nginx_pid ] 
        if [ $? -eq 0 ];then
                $path -s quit
                echo "nginx已关闭"
        fi
;;
	restart)
#       netstat -anput | grep nginx &>/dev/null  
        [ -e $nginx_pid ]
        if [ $? -eq 0 ];then
                $path -s quit
                $path
                echo "nginx已重启"
	else
		echo"nginx未启动请先启动"	
        fi 
;;
	status)
	netstat -anput | grep nginx &>/dev/null
	if [ $? -eq 0 ];then
		echo "nginx已启动"
	else
		echo "nginx未启动"
	fi
;;
	*)
	echo "Usage: bash nginx.sh {start|stop|restart}"
esac